<?php
namespace app\admin\controller;

use app\BaseController;
use app\admin\service\AdminUserService;
use app\admin\service\AdminRoleService;

class Home extends BaseController
{	
    public function index(AdminUserService $serviceUser)
    {
        $userInfo = $serviceUser->getInfo(session('admin_user'));
        $this->assign('userInfo', $userInfo);

        return view();
    }
	
	//门面
	public function console()
    {
        return view();
    }
	
	//消息中心
	public function message()
    {
        return view();
    }
	
	//基本资料
	public function my(AdminUserService $serviceUser,AdminRoleService $serviceRole)
    {
        $request = $this->request;
        if($request->method() == 'POST'){
            $input = input();
            unset($input['file']);
            $res = $serviceUser->edit(['id'=>session('admin_user')], $input);
            if($res){
                return json(['code' => 0, 'msg' => '更新成功']);
            }else{
                return json(['code' => -1, 'msg' => '更新失败']);
            }
        }else{
            $userInfo = $serviceUser->getInfo(session('admin_user'));
            $this->assign('userInfo', $userInfo);

            $roleList = $serviceRole->getList(['status'=>1],'id,name');
            $this->assign('roleList', $roleList);

            return view();
        }
    }
	
	//修改密码
	public function password()
	{
		return view();
	}
	
	//搜索
	public function search()
    {
        return view();
    }
	
	//关于
	public function about()
    {
        return view();
    }
	
	//退出
	public function logout()
	{
		$data = [
			'url' => '/admin/index/index'
		];
        return json(['code'=>0,'msg'=>'ok','data'=>$data]);
		//return redirect('admin/index/index');
	}
}
